/**
 * MP Software.
 */
package controllers;

import helpers.ElectronicIdConstant;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.math.BigDecimal;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.inject.Inject;

import models.Payment;
import models.Payroll;
import models.PayrollPeriod;
import models.Rate;

import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.ss.usermodel.CreationHelper;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;

import play.mvc.Controller;
import service.BillingCalculator;
import service.PaymentDeductionFacade;
import service.PayrollRegisterResult;
import service.PayrollRegisterService;
import service.RateResolver;
import service.calculator.aristocrat.AristocratBillingCalculatorImpl;
import service.calculator.aristocrat.AristocratPaymentType;
import service.calculator.bagnetified.sanmateo.BagnetifiedSanMateoBillingCalculatorImpl;
import service.calculator.bagnetified.sanmateo.BagnetifiedSanMateoPaymentType;
import service.calculator.bonchon.BonchonBillingCalculatorImpl;
import service.calculator.bonchon.BonchonPaymentType;
import service.calculator.bonchon.baguio.BonchonBaguioBillingCalculatorImpl;
import service.calculator.bonchon.batangas.BonchonBatangasBillingCalculatorImpl;
import service.calculator.bonchon.lumina.BonchonLuminaBillingCalculatorImpl;
import service.calculator.bonchon.marquee.BonchonMarqueeBillingCalculatorImpl;
import service.calculator.bonchon.paseo.BonchonPaseoBillingCalculatorImpl;
import service.calculator.crystalite.CrystaliteBillingCalculatorImpl;
import service.calculator.crystalite.CrystalitePaymentType;
import service.calculator.crystalite.laguna.CrystaliteLagunaBillingCalculatorImpl;
import service.calculator.jeron.JeronBillingCalculatorImpl;
import service.calculator.jeron.JeronPaymentType;
import service.calculator.sonic.SonicBillingCalculatorImpl;
import service.calculator.sonic.SonicPaymentType;
import service.calculator.sonic.two.Sonic2BillingCalculatorImpl;
import controllers.views.PaymentTypeView;

/**
 * @author Jeremiah John M. Macariola
 * 
 */
public class PayrollBillingDownload extends Controller {

	@Inject
	private static RateResolver rateResolver;

	@Inject
	private static PaymentDeductionFacade paymentDeductionFacade;

	@Inject
	private static PayrollRegisterService payrollRegisterService;

	@Inject
	private static BonchonBillingCalculatorImpl bonchonBillingCalculator = new BonchonBillingCalculatorImpl();

	@Inject
	private static BonchonBatangasBillingCalculatorImpl bonchonBatangasBillingCalculator = new BonchonBatangasBillingCalculatorImpl();

	@Inject
	private static BonchonPaseoBillingCalculatorImpl bonchonPaseoBillingCalculator = new BonchonPaseoBillingCalculatorImpl();

	@Inject
	private static BonchonBaguioBillingCalculatorImpl bonchonBaguioBillingCalculator = new BonchonBaguioBillingCalculatorImpl();

	@Inject
	private static BonchonMarqueeBillingCalculatorImpl bonchonMarqueeBillingCalculator = new BonchonMarqueeBillingCalculatorImpl();

	@Inject
	private static BonchonLuminaBillingCalculatorImpl bonchonLuminaBillingCalculator = new BonchonLuminaBillingCalculatorImpl();

	@Inject
	private static AristocratBillingCalculatorImpl aristocratBillingCalculator = new AristocratBillingCalculatorImpl();

	@Inject
	private static CrystaliteBillingCalculatorImpl crystaliteBillingCalculator = new CrystaliteBillingCalculatorImpl();

	@Inject
	private static CrystaliteLagunaBillingCalculatorImpl crystaliteLagunaBillingCalculator = new CrystaliteLagunaBillingCalculatorImpl();

	@Inject
	private static JeronBillingCalculatorImpl jeronBillingCalculator = new JeronBillingCalculatorImpl();

	@Inject
	private static SonicBillingCalculatorImpl sonicBillingCalculator = new SonicBillingCalculatorImpl();

	@Inject
	private static Sonic2BillingCalculatorImpl sonic2BillingCalculator = new Sonic2BillingCalculatorImpl();

	@Inject
	private static BagnetifiedSanMateoBillingCalculatorImpl bagnetifiedSanMateoBillingCalculatorImpl = new BagnetifiedSanMateoBillingCalculatorImpl();

	public static void download(Long payrollPeriodId) {
		PayrollPeriod payrollPeriod = PayrollPeriod.findById(payrollPeriodId);
		createExcelSheet(payrollPeriod);
	}

	private static void createExcelSheet(final PayrollPeriod payrollPeriod) {
		try {
			generateExcelDocument(payrollPeriod);

		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}

	}

	private static void generateExcelDocument(final PayrollPeriod payrollPeriod)
			throws IOException {
		final Workbook wb = new HSSFWorkbook();
		final CreationHelper createHelper = wb.getCreationHelper();
		final Sheet sheet = wb.createSheet("new sheet");

		/*
		 * TODO: Refactor this to service layer.
		 */
		final String electronicId = payrollPeriod.client.electronicId;
		final BillingCalculator billingCalculator = retrieveBillingCalculator(electronicId);
		final Rate rate = rateResolver.getRate(electronicId);

		/*
		 * Create the header.
		 */
		Row row = sheet.createRow((short) 0);
		Cell cell = row.createCell(0);
		cell.setCellValue("DAY BY DAY SERVICE COOPERATIVE");
		row = sheet.createRow((short) 1);
		cell = row.createCell(0);
		cell.setCellValue("BILLING SCHEDULE");
		row = sheet.createRow((short) 2);
		cell = row.createCell(0);
		cell.setCellValue("PERIOD COVERED: "
				+ payrollPeriod.getFromDateFormatted() + " - "
				+ payrollPeriod.getToDateFormatted());
		row = sheet.createRow((short) 3);
		cell = row.createCell(0);
		cell.setCellValue(payrollPeriod.client.name);

		/*
		 * TODO: Refactor this to service layer. Map of total payment types.
		 */
		final Map<String, Float> totalPaymentHrTypes = new HashMap<String, Float>();

		/*
		 * Create the Payment type header.
		 */
		row = sheet.createRow((short) 4);
		int paymentDeductionTypeIndex = 1;
		final List<PaymentTypeView> paymentTypes = paymentDeductionFacade
				.getPaymentTypes(electronicId);
		for (PaymentTypeView paymentTypeView : paymentTypes) {
			if (isPaymentTypeBillable(electronicId, paymentTypeView)) {
				cell = row.createCell(paymentDeductionTypeIndex);
				cell.setCellValue(paymentTypeView.name);
				paymentDeductionTypeIndex += 2;

				/*
				 * TODO: Refactor this to service layer.
				 */
				totalPaymentHrTypes.put(paymentTypeView.name,
						Float.valueOf(0.0F));
			}
		}

		/*
		 * Set the style for numeric cells.
		 */
		CellStyle style = wb.createCellStyle();
		style.setAlignment(CellStyle.ALIGN_RIGHT);
		style.setDataFormat(createHelper.createDataFormat().getFormat(
				"#,##0.00"));

		/*
		 * Iterate over employee and print its payments and deductions.
		 */
		PayrollRegisterResult result = payrollRegisterService.process(
				electronicId, payrollPeriod);
		Map<String, Float> employeePayments = result.getEmployeePayments();
		List<Payroll> payrolls = getPayrolls(payrollPeriod);
		short rowIndex = 5;
		for (Payroll payroll : payrolls) {
			row = sheet.createRow(rowIndex);

			int columnIndex = 0;
			cell = row.createCell(columnIndex);
			cell.setCellValue(payroll.employee.name);
			columnIndex++;

			final Long employeeId = payroll.employee.id;

			for (PaymentTypeView paymentTypeView : paymentTypes) {
				boolean ispaymentTypeBillable = isPaymentTypeBillable(
						electronicId, paymentTypeView);
				if (ispaymentTypeBillable) {

					Float paymentHr = employeePayments.get(employeeId
							+ paymentTypeView.name);
					if (paymentHr != null) {

						/*
						 * Payment Hour
						 */
						cell = row.createCell(columnIndex);
						cell.setCellValue(paymentHr);
						cell.setCellStyle(style);
						cell.setCellType(Cell.CELL_TYPE_NUMERIC);

						/*
						 * Payment Value
						 */
						columnIndex++;
						final Payment payment = new Payment(paymentTypeView.name,
								paymentHr, payrolls.get(0)); // TODO: How to get the correct payroll here!!?
						final BigDecimal paymentValue = billingCalculator.calculatePayment(rate, payment);
						cell = row.createCell(columnIndex);
						cell.setCellValue(paymentValue.doubleValue());
						cell.setCellStyle(style);
						cell.setCellType(Cell.CELL_TYPE_NUMERIC);

						/*
						 * TODO: Refactor this to service layer.
						 */
						totalPaymentHrTypes.put(paymentTypeView.name,
								totalPaymentHrTypes.get(paymentTypeView.name)
										+ (Float.valueOf(paymentHr)));

					} else {
						columnIndex++;
					}

					columnIndex++;
				}
			}

			rowIndex++;
		}

		/*
		 * Create the Total number of hours row.
		 */
		row = sheet.createRow(rowIndex);
		cell = row.createCell(0);
		cell.setCellValue("TOTAL NO. OF HOURS");
		int totalNumberOfHrsColumnIndex = 1;
		for (PaymentTypeView paymentTypeView : paymentTypes) {
			if (isPaymentTypeBillable(electronicId, paymentTypeView)) {
				cell = row.createCell(totalNumberOfHrsColumnIndex);
				cell.setCellValue(totalPaymentHrTypes.get(paymentTypeView.name));
				cell.setCellStyle(style);
				totalNumberOfHrsColumnIndex += 2;
			}
		}
		rowIndex++;

		/*
		 * Create the billing rates.
		 */
		row = sheet.createRow(rowIndex);
		cell = row.createCell(0);
		cell.setCellValue("RATE PER HOUR");
		int billingRatePerPaymentColumnIndex = 1;
		for (PaymentTypeView paymentTypeView : paymentTypes) {
			if (isPaymentTypeBillable(electronicId, paymentTypeView)) {
				final Payment payment = new Payment(paymentTypeView.name,
						Float.valueOf(1F), payrolls.get(0)); // TODO: How to get the correct payroll here!!?
				final BigDecimal billingPayment = billingCalculator.calculatePayment(
						rate, payment);

				cell = row.createCell(billingRatePerPaymentColumnIndex);
				if (billingPayment != null) {
					cell.setCellValue(billingPayment.doubleValue());
				}
				cell.setCellStyle(style);
				billingRatePerPaymentColumnIndex += 2;
			}
		}
		rowIndex++;

		/*
		 * Create the Total billing amount per payment.
		 */
		row = sheet.createRow(rowIndex);
		cell = row.createCell(0);
		cell.setCellValue("BILLING AMOUNT PER PAYMENT");
		int billingAmountPerPaymentColumnIndex = 1;
		for (PaymentTypeView paymentTypeView : paymentTypes) {
			if (isPaymentTypeBillable(electronicId, paymentTypeView)) {
				final Payment payment = new Payment(paymentTypeView.name,
						totalPaymentHrTypes.get(paymentTypeView.name), payrolls.get(0)); // TODO: How to get the correct payroll here!!?
				final BigDecimal billingPayment = billingCalculator.calculatePayment(
						rate, payment);

				cell = row.createCell(billingAmountPerPaymentColumnIndex);
				if (billingPayment != null) {
					cell.setCellValue(billingPayment.doubleValue());
				}
				cell.setCellStyle(style);
				billingAmountPerPaymentColumnIndex += 2;
			}
		}

		/*
		 * Create and write the file.
		 */
		DateFormat df = new SimpleDateFormat("MMMddyyyy");
		String fileName = "PayrollBilling-" + df.format(payrollPeriod.fromDate)
				+ '-' + df.format(payrollPeriod.toDate);
		df = new SimpleDateFormat("HHmmssMMMddyyyy");
		fileName = fileName + '-' + df.format(new Date());
		fileName = fileName + ".xls";
		final FileOutputStream fileOut = new FileOutputStream(fileName);
		wb.write(fileOut);
		fileOut.close();
	}

	private static BillingCalculator retrieveBillingCalculator(
			final String electronicId) {
		BillingCalculator billingCalculator = null;

		if (ElectronicIdConstant.BONCHON.equals(electronicId)) {
			billingCalculator = bonchonBillingCalculator;
		} else if (ElectronicIdConstant.BONCHON_BATANGAS.equals(electronicId)) {
			billingCalculator = bonchonBatangasBillingCalculator;
		} else if (ElectronicIdConstant.BONCHON_PASEO.equals(electronicId)) {
			billingCalculator = bonchonPaseoBillingCalculator;
		} else if (ElectronicIdConstant.BONCHON_BAGUIO.equals(electronicId)) {
			billingCalculator = bonchonBaguioBillingCalculator;
		} else if (ElectronicIdConstant.BONCHON_MARQUEE.equals(electronicId)) {
			billingCalculator = bonchonMarqueeBillingCalculator;
		} else if (ElectronicIdConstant.BONCHON_LUMINA.equals(electronicId)) {
			billingCalculator = bonchonLuminaBillingCalculator;
		} else if (ElectronicIdConstant.ARISTOCRAT.equals(electronicId)) {
			billingCalculator = aristocratBillingCalculator;
		} else if (ElectronicIdConstant.CRYSTALITE.equals(electronicId)) {
			billingCalculator = crystaliteBillingCalculator;
		} else if (ElectronicIdConstant.CRYSTALITE_LAGUNA.equals(electronicId)) {
			billingCalculator = crystaliteLagunaBillingCalculator;
		} else if (ElectronicIdConstant.JERON.equals(electronicId)) {
			billingCalculator = jeronBillingCalculator;
		} else if (ElectronicIdConstant.SONIC.equals(electronicId)) {
			billingCalculator = sonicBillingCalculator;
		} else if (ElectronicIdConstant.SONIC_2.equals(electronicId)) {
			billingCalculator = sonic2BillingCalculator;
		} else if (ElectronicIdConstant.BAGNETIFIED_SANMATEO.equals(electronicId)) {
			billingCalculator = bagnetifiedSanMateoBillingCalculatorImpl;
		}

		return billingCalculator;
	}

	private static boolean isPaymentTypeBillable(final String electronicId,
			final PaymentTypeView paymentTypeView) {
		boolean isPaymentTypeBillable = false;
		String paymentTypeViewName = paymentTypeView.name;

		if (ElectronicIdConstant.BONCHON.equals(electronicId)
				|| ElectronicIdConstant.BONCHON_BATANGAS.equals(electronicId)
				|| ElectronicIdConstant.BONCHON_PASEO.equals(electronicId)
				|| ElectronicIdConstant.BONCHON_BAGUIO.equals(electronicId)
				|| ElectronicIdConstant.BONCHON_MARQUEE.equals(electronicId)
				|| ElectronicIdConstant.BONCHON_LUMINA.equals(electronicId)) {
			boolean isNotAdj = !BonchonPaymentType.ADJ.name().equals(
					paymentTypeViewName);
			boolean isNotAdjRt = !BonchonPaymentType.ADJ_RT.name().equals(
					paymentTypeViewName);
			boolean isNotAdjOt = !BonchonPaymentType.ADJ_OT.name().equals(
					paymentTypeViewName);
			boolean isNotAdjNdrt = !BonchonPaymentType.ADJ_NDRT.name().equals(
					paymentTypeViewName);
			boolean isNotAdjLhrt = !BonchonPaymentType.ADJ_LHRT.name().equals(
					paymentTypeViewName);
			boolean isNotAdjLhot = !BonchonPaymentType.ADJ_LHOT.name().equals(
					paymentTypeViewName);
			boolean isNotAdjShrt = !BonchonPaymentType.ADJ_SHRT.name().equals(
					paymentTypeViewName);
			boolean isNotAdjShot = !BonchonPaymentType.ADJ_SHOT.name().equals(
					paymentTypeViewName);
			boolean isNotAdjRdrt = !BonchonPaymentType.ADJ_RDRT.name().equals(
					paymentTypeViewName);
			boolean isNotAdjRdot = !BonchonPaymentType.ADJ_RDOT.name().equals(
					paymentTypeViewName);
			boolean isNotAdjSea = !BonchonPaymentType.ADJ_SEA.name().equals(
					paymentTypeViewName);
			boolean isNotTmp = !BonchonPaymentType.TMP.name().equals(paymentTypeViewName);
			isPaymentTypeBillable = isNotAdj && isNotAdjRt && isNotAdjOt && isNotAdjNdrt
					&& isNotAdjLhrt && isNotAdjLhot && isNotAdjShrt && isNotAdjShot
					&& isNotAdjRdrt && isNotAdjRdot && isNotTmp && isNotAdjSea;

		} else if (ElectronicIdConstant.ARISTOCRAT.equals(electronicId)) {
			boolean isNotAdj = !AristocratPaymentType.ADJ.name().equals(
					paymentTypeViewName);
			boolean isNotAdjRt = !AristocratPaymentType.ADJ_RT.name().equals(
					paymentTypeViewName);
			boolean isNotAdjOt = !AristocratPaymentType.ADJ_OT.name().equals(
					paymentTypeViewName);
			boolean isNotAdjNdrt = !AristocratPaymentType.ADJ_NDRT.name().equals(
					paymentTypeViewName);
			boolean isNotAdjHp = !AristocratPaymentType.ADJ_HP.name().equals(
					paymentTypeViewName);
			boolean isNotAdjLhot = !AristocratPaymentType.ADJ_LHOT.name().equals(
					paymentTypeViewName);
			boolean isNotAdjShrt = !AristocratPaymentType.ADJ_SHRT.name().equals(
					paymentTypeViewName);
			boolean isNotAdjShot = !AristocratPaymentType.ADJ_SHOT.name().equals(
					paymentTypeViewName);
			boolean isNotAdjRdrt = !AristocratPaymentType.ADJ_RDRT.name().equals(
					paymentTypeViewName);
			boolean isNotAdjRdot = !AristocratPaymentType.ADJ_RDOT.name().equals(
					paymentTypeViewName);
			isPaymentTypeBillable = isNotAdj && isNotAdjRt && isNotAdjOt && isNotAdjNdrt
					&& isNotAdjHp && isNotAdjLhot && isNotAdjShrt && isNotAdjShot
					&& isNotAdjRdrt && isNotAdjRdot;

		} else if (ElectronicIdConstant.CRYSTALITE.equals(electronicId)
				|| ElectronicIdConstant.CRYSTALITE_LAGUNA.equals(electronicId)) {
			boolean isNotAdj = !CrystalitePaymentType.ADJ.name().equals(
					paymentTypeViewName);
			boolean isNotAdjRt = !CrystalitePaymentType.ADJ_RT.name().equals(
					paymentTypeViewName);
			boolean isNotAdjOt = !CrystalitePaymentType.ADJ_OT.name().equals(
					paymentTypeViewName);
			boolean isNotAdjNdrt = !CrystalitePaymentType.ADJ_NDRT.name().equals(
					paymentTypeViewName);
			boolean isNotAdjLhrt = !CrystalitePaymentType.ADJ_LHRT.name().equals(
					paymentTypeViewName);
			boolean isNotAdjLhot = !CrystalitePaymentType.ADJ_LHOT.name().equals(
					paymentTypeViewName);
			boolean isNotAdjShrt = !CrystalitePaymentType.ADJ_SHRT.name().equals(
					paymentTypeViewName);
			boolean isNotAdjShot = !CrystalitePaymentType.ADJ_SHOT.name().equals(
					paymentTypeViewName);
			boolean isNotAdjRdrt = !CrystalitePaymentType.ADJ_RDRT.name().equals(
					paymentTypeViewName);
			boolean isNotAdjRdot = !CrystalitePaymentType.ADJ_RDOT.name().equals(
					paymentTypeViewName);
			boolean isNotSvcChrg = !CrystalitePaymentType.SVC_CHRG.name().equals(
					paymentTypeViewName);
			isPaymentTypeBillable = isNotAdj && isNotAdjRt && isNotAdjOt && isNotAdjNdrt
			&& isNotAdjLhrt && isNotAdjLhot && isNotAdjShrt && isNotAdjShot
			&& isNotAdjRdrt && isNotAdjRdot && isNotSvcChrg;
		} else if (ElectronicIdConstant.JERON.equals(electronicId)) {
			boolean isNotAdj = !JeronPaymentType.ADJ.name().equals(
					paymentTypeViewName);
			boolean isNotAdjRt = !JeronPaymentType.ADJ_RT.name().equals(
					paymentTypeViewName);
			boolean isNotAdjOt = !JeronPaymentType.ADJ_OT.name().equals(
					paymentTypeViewName);
			boolean isNotAdjNdrt = !JeronPaymentType.ADJ_NDRT.name().equals(
					paymentTypeViewName);
			boolean isNotAdjLhrt = !JeronPaymentType.ADJ_LHRT.name().equals(
					paymentTypeViewName);
			boolean isNotAdjLhot = !JeronPaymentType.ADJ_LHOT.name().equals(
					paymentTypeViewName);
			boolean isNotAdjShrt = !JeronPaymentType.ADJ_SHRT.name().equals(
					paymentTypeViewName);
			boolean isNotAdjShot = !JeronPaymentType.ADJ_SHOT.name().equals(
					paymentTypeViewName);
			boolean isNotAdjRdrt = !JeronPaymentType.ADJ_RDRT.name().equals(
					paymentTypeViewName);
			boolean isNotAdjRdot = !JeronPaymentType.ADJ_RDOT.name().equals(
					paymentTypeViewName);
			boolean isNotSvcChrg = !JeronPaymentType.SVC_CHRG.name().equals(
					paymentTypeViewName);
			isPaymentTypeBillable = isNotAdj && isNotAdjRt && isNotAdjOt && isNotAdjNdrt
			&& isNotAdjLhrt && isNotAdjLhot && isNotAdjShrt && isNotAdjShot
			&& isNotAdjRdrt && isNotAdjRdot && isNotSvcChrg;
		} else if (ElectronicIdConstant.SONIC.equals(electronicId)
				|| ElectronicIdConstant.SONIC_2.equals(electronicId)) {
			boolean isNotAdj = !SonicPaymentType.ADJ.name().equals(
					paymentTypeViewName);
			boolean isNotAdjRt = !SonicPaymentType.ADJ_RT.name().equals(
					paymentTypeViewName);
			boolean isNotAdjOt = !SonicPaymentType.ADJ_OT.name().equals(
					paymentTypeViewName);
			boolean isNotAdjRdrt = !SonicPaymentType.ADJ_RDRT.name().equals(
					paymentTypeViewName);
			boolean isNotAdjHp = !SonicPaymentType.ADJ_HP.name().equals(
					paymentTypeViewName);
			isPaymentTypeBillable = isNotAdj && isNotAdjRt && isNotAdjOt
					&& isNotAdjRdrt && isNotAdjHp;
		} else if (ElectronicIdConstant.BAGNETIFIED_SANMATEO.equals(electronicId)) {
			boolean isNotAdj = !BagnetifiedSanMateoPaymentType.ADJ.name().equals(
					paymentTypeViewName);
			boolean isNotAdjRt = !BagnetifiedSanMateoPaymentType.ADJ_RT.name().equals(
					paymentTypeViewName);
			boolean isNotAdjOt = !BagnetifiedSanMateoPaymentType.ADJ_OT.name().equals(
					paymentTypeViewName);
			boolean isNotAdjNdrt = !BagnetifiedSanMateoPaymentType.ADJ_NDRT.name().equals(
					paymentTypeViewName);
			boolean isNotAdjLhrt = !BagnetifiedSanMateoPaymentType.ADJ_LHRT.name().equals(
					paymentTypeViewName);
			boolean isNotAdjLhot = !BagnetifiedSanMateoPaymentType.ADJ_LHOT.name().equals(
					paymentTypeViewName);
			boolean isNotAdjShrt = !BagnetifiedSanMateoPaymentType.ADJ_SHRT.name().equals(
					paymentTypeViewName);
			boolean isNotAdjShot = !BagnetifiedSanMateoPaymentType.ADJ_SHOT.name().equals(
					paymentTypeViewName);
			boolean isNotAdjRdrt = !BagnetifiedSanMateoPaymentType.ADJ_RDRT.name().equals(
					paymentTypeViewName);
			boolean isNotAdjRdot = !BagnetifiedSanMateoPaymentType.ADJ_RDOT.name().equals(
					paymentTypeViewName);
			boolean isNotSvcChrg = !BagnetifiedSanMateoPaymentType.SVC_CHRG.name().equals(
					paymentTypeViewName);
			isPaymentTypeBillable = isNotAdj && isNotAdjRt && isNotAdjOt && isNotAdjNdrt
			&& isNotAdjLhrt && isNotAdjLhot && isNotAdjShrt && isNotAdjShot
			&& isNotAdjRdrt && isNotAdjRdot && isNotSvcChrg;
		}

		return isPaymentTypeBillable;
	}

	private static List<Payroll> getPayrolls(PayrollPeriod payrollPeriod) {
		return payrollRegisterService.loadPayrolls(payrollPeriod);
	}

}
